/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.persistence.test.bean;

import java.util.HashSet;
import java.util.Set;

import com.genia.toolbox.persistence.bean.Persistable;
import com.genia.toolbox.persistence.criteria.PropertyField;
import com.genia.toolbox.persistence.criteria.SimplePropertyField;

/**
 * An example persistent object.
 */
public class PersistentObjectB
    implements Persistable<Long>
{
  /**
   * the identifier property descriptor.
   */
  public static final SimplePropertyField<Long> NAME_IDENTIFIER = PropertyField.create(Long.class, "identifier");

  /**
   * the name of the variable varPersistentObjectC.
   */
  public static final PropertyField<Set<PersistentObjectC>, PersistentObjectC> NAME_VAR_PERSISTENT_OBJECT_C = PropertyField.create(Set.class, PersistentObjectC.class, "varPersistentObjectC");

  /**
   * the identifier of the class.
   */
  private Long identifier;

  /**
   * a variable of type <code>Collection&lt;PersistentObjectC&gt;</code>.
   */
  private Set<PersistentObjectC> varPersistentObjectC;



  /**
   * the default constructor of the class.
   */
  public PersistentObjectB()
  {
    varPersistentObjectC = new HashSet<PersistentObjectC>();
  }



  /**
   * getter for the identifier property.
   * 
   * @return the identifier
   */
  public Long getIdentifier()
  {
    return identifier;
  }



  /**
   * setter for the identifier property.
   * 
   * @param identifier
   *          the identifier to set
   */
  public void setIdentifier(final Long identifier)
  {
    this.identifier = identifier;
  }



  /**
   * getter for the varPersistentObjectC property.
   * 
   * @return the varPersistentObjectC
   */
  public Set<PersistentObjectC> getVarPersistentObjectC()
  {
    return varPersistentObjectC;
  }



  /**
   * Returns a hash code value for the object. This method is supported for the
   * benefit of hashtables such as those provided by
   * <code>java.util.Hashtable</code>.
   * 
   * @return a hash code value for this object.
   */
  @Override
  public int hashCode()
  {
    if (getIdentifier() != null) {
      return getIdentifier().intValue();
    }
    return super.hashCode();
  }



  /**
   * setter for the varPersistentObjectC property.
   * 
   * @param varPersistentObjectC
   *          the varPersistentObjectC to set
   */
  public void setVarPersistentObjectC(final Set<PersistentObjectC> varPersistentObjectC)
  {
    this.varPersistentObjectC = varPersistentObjectC;
  }



  /**
   * Indicates whether some other object is "equal to" this one.
   * 
   * @param obj
   *          the reference object with which to compare.
   * @return <code>true</code> if this object is the same as the obj argument;
   *         <code>false</code> otherwise.
   */
  @Override
  public boolean equals(final Object obj)
  {
    if (obj == null) {
      return false;
    }
    if (obj == this) {
      return true;
    }
    if (identifier == null) {
      return false;
    }
    if (obj instanceof PersistentObjectB) {
      final PersistentObjectB otherB = (PersistentObjectB) obj;
      return identifier.equals(otherB.identifier);
    }
    return false;
  }

}
